<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
        <meta name="format-detection" content="telephone=no">
        <title>我的</title>
        <link href="/Public/Home/css/weui.min.css" rel="stylesheet">
       <link rel="stylesheet" href="/Public/Home/SaleManager/stylesheets/distributorindex.css">

    </head>
<body>
<header class="all_header">
    <a class="h_back h_back_1 distrubutor" href="javascript:void(0)" data-role-id="<?php echo ($myself["role_id"]); ?>">
      <img src="/Public/Home/SaleManager/images/back_icon.png" alt="">
    </a> 
    <span class="h_title">诊所分配</span> 
    <a class="h_add" href="javascript:void(0)"></a>
</header>
<!-- 分配列表 -->
<section class="distribution-list qc-wrap" id="select-more">
   <div class="dis-list-wrap" id="select-list">
     <ul>
     <?php if(is_array($clinics)): $i = 0; $__LIST__ = $clinics;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$clinic): $mod = ($i % 2 );++$i;?><li data-clinic_id='<?php echo ($clinic["id"]); ?>'>
          <i></i>
          <h6 class="name"><strong><?php echo ($clinic["clinic_name"]); ?></strong>
          	<?php if($clinic["type"] == 1): ?><span style='color:red' >&nbsp;目标诊所</span>
          		<?php else: ?><span style='color:green'>&nbsp;我的诊所</span><?php endif; ?>
          </h6>
          <p class="sale-man">
						<?php if(is_array($lists)): $i = 0; $__LIST__ = $lists;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$n): $mod = ($i % 2 );++$i; if($n["id"] == $clinic["saleman_id"]): switch($n["role_id"]): case "5": ?>业务员:<?php break;?>
								    <?php case "4": ?>县总:<?php break;?>
								    <?php case "3": ?>地总:<?php break;?>
								    <?php default: ?>业务员:<?php endswitch;?>
          						<?php echo ($n["real_name"]); endif; endforeach; endif; else: echo "" ;endif; ?>
          </p>
          <p class="address">地　址：<?php echo ($clinic["clinic_address"]); ?></p>
        </li><?php endforeach; endif; else: echo "" ;endif; ?>
     </ul>
   </div>
   <div class="dis-btn">
          <a href="#" class="w-button" id="btn_g">
            分配
          </a>        
      </div>
</section>
<!-- 分配列表 -->
<!-- 单选列表 -->
<section class="distribution-list qc-wrap" id="select-one">
   <div class="dis-list-wrap">
     <span class="close-btn iconfont">
       &#xe635;
     </span>
     <ul>
	     <?php if(is_array($lists)): $i = 0; $__LIST__ = $lists;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$list): $mod = ($i % 2 );++$i;?><li data-saleman_id='<?php echo ($list["id"]); ?>'>
	          <i></i>
	          <h6 class="name" ><?php echo ($list["real_name"]); ?><h6>
	        </li><?php endforeach; endif; else: echo "" ;endif; ?>
     </ul>
   </div>
   <div class="dis-btn">
          <a href="#" class="w-button" id="btn_one">
            确定
          </a>        
      </div>
</section>
<!-- 单选列表 -->
       <!-- 弹窗 -->    
      <div class="ui-dialog-ok" id="ok-success">
          <div class="ui-dialog-cnt">
                  <div class="header-title">
                       <h4 class="title" >分配成功</h4>
                  </div>
                  <div class="close-btn">
                      <button type="button" class="simple-close" id="dialogButton">知道了</button> 
                  </div>
          </div>        
      </div>
     <div class="js_dialog" id="iosDialog1" style="display: none;">
    <div class="weui-mask"></div>
    <div class="weui-dialog">
        <div class="weui-dialog__hd"><strong class="weui-dialog__title">提示</strong></div>
        <div class="weui-dialog__bd confir_content"></div>
        <div class="weui-dialog__ft">
            <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_default cancel-btn">取消</a>
            <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_primary ok-btn">确定</a>
        </div>
    </div>
</div>


 <div class="js_dialog" id="iosDialog_2" style="display: none;">
    <div class="weui-mask"></div>
    <div class="weui-dialog">
        <div class="weui-dialog__hd"><strong class="weui-dialog__title">提示</strong></div>
        <div class="weui-dialog__bd confir_content"></div>
        <div class="weui-dialog__ft">
            <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_default cancels-btn">取消</a>
            <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_primary oks-btn">确定</a>
        </div>
    </div>
</div> 

<div class="js_dialog" id="iosDialog2" style="display: none;">
    <div class="weui-mask"></div>
    <div class="weui-dialog">
        <div class="weui-dialog__bd sure-info"></div>
        <div class="weui-dialog__ft">
            <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_primary sure-btn" pos_url="location.href">知道了</a>
        </div>
    </div>
</div>

<div class="js_dialog" id="signiosDialog2" style="display: none;">
    <div class="weui-mask"></div>
    <div class="weui-dialog">
        <div class="weui-dialog__bd confir_content"></div>
        <div class="weui-dialog__ft">
        		<a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_default signcancels-btn">知道了</a>
            <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_primary sure-btn" pos_url="location.href">重试</a>
        </div>
    </div>
</div>

<div class="js_dialog" id="iosDialogsign" style="display: none;">
    <div class="weui-mask"></div>
    <div class="weui-dialog">
        <div class="weui-dialog__bd sure-info"></div>
        <div class="weui-dialog__ft">
            <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_primary signsure-btn" pos_url="location.href">知道了</a>
        </div>
    </div>
</div>
<script>
    $('.cancel-btn').on('click', function () {
        $('#iosDialog1').hide(200);
    });
    $('.sure-btn').on('click', function () {
        $('#iosDialog2').hide(200);

        var pos_url = $(this).attr('pos_url');

        if (pos_url != "") {
            location.href = location.href;
        }


    });
</script>  
    <div class="js_dialog" id="confirm_dialog" style="display: none;">
      <div class="weui-mask"></div>
      <div class="weui-dialog">
        <div class="weui-dialog__bd"></div>
        <div class="weui-dialog__ft">
            <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_primary">确 定</a>
        </div>
      </div>
    </div>
    <div class="js_dialog" id="iosDialog1" style="display: none;">
    <div class="weui-mask"></div>
    <div class="weui-dialog">
        <div class="weui-dialog__hd"><strong class="weui-dialog__title">提示</strong></div>
        <div class="weui-dialog__bd confir_content"></div>
        <div class="weui-dialog__ft">
            <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_default cancel-btn">取消</a>
            <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_primary ok-btn">确定</a>
        </div>
    </div>
</div>
 <div class="js_dialog" id="jsconfiroms" style="display: none;">
    <div class="weui-mask"></div>
    <div class="weui-dialog">
        <div class="weui-dialog__hd"><strong class="weui-dialog__title">提示</strong></div>
        <div class="weui-dialog__bd confir_content"></div>
        <div class="weui-dialog__ft">
            
            <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_primary oksss-btn">确定</a>
            <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_default cancelsss-btn">取消</a>
        </div>
    </div>
</div>


  <script type="text/javascript">
	var saleManagerStatus; //操作返回状态
	$(document).ready(function() { 
		saleManagerStatus='';
		saleManagerStatus ='<?php echo ($status); ?>';  //success,成功；error,错误
		msg ='<?php echo ($msg); ?>';
		if(saleManagerStatus=='success'||saleManagerStatus=='validatefail'){
			$('.weui-dialog__bd').html(msg);
     		$('#confirm_dialog').css('display','block');
     		//saleManagerStatus='formSubmitTrue';
		}
		if(saleManagerStatus=='error'){ 
			$('.weui-dialog__bd').html(msg);
     		$('#confirm_dialog').css('display','block');
     		//saleManagerStatus='formSubmitTrue';
		}
	}); 
	//关闭弹出框
	$(document).on('click','.weui-dialog__btn_primary',function(){
		$('#confirm_dialog').css('display','none');
		if(saleManagerStatus=='error'){
			history.go(-1);
		}
	}); 
	
	$(document).on('click','.cancelsss-btn',function(){
		$('#jsconfiroms').css('display','none');
	});
  </script>
<!-- 弹窗 -->  

 <script src="/Public/Home/js/zepto.min.js"></script>
<script src = "/Public/Home/SaleManager/js/Common.js"></script>
<script src = "/Public/Home/SaleManager/js/androidback.js"></script>
 <script type="text/javascript">
	var sessioncode;
	var nosesstion_url;
	var returnStatus;
   $(function(){
         $("#select-more").find("li").click(function(){
             var me=$(this);
             if(me.hasClass("selected")){
                 me.removeClass("selected")
             }
             else{
                 me.addClass("selected")
             }
         })
         $("#select-one").find("li").click(function(){
             var me=$(this);
             $("#select-one").find("li").removeClass("selected");
             me.addClass("selected");
         })
         // 分配按钮
         $("#btn_g").click(function(){
        	 	clinicObj=$('#select-list').find('.selected');
      		if(clinicObj.length==0){
      			 $('#iosDialog2').find('.sure-info').html('请选择诊所');
                  $('#iosDialog2').show(200);
                  return false;
      		}
            $("#select-more").css("display","none");
            $("#select-one").css("display","block");
         })
         $("#select-one .close-btn").click(function(){
            $("#select-more").css("display","block");
            $("#select-one").css("display","none");
         })
         // 弹窗
         $("#btn_one").click(function(){
     		//1.获取所有选中诊所id
     		clinicCheck='{';
     		clinicObj=$('#select-list').find('.selected');
     		if(clinicObj.length==0){
     			 $('#iosDialog2').find('.sure-info').html('请选择诊所');
                 $('#iosDialog2').show(200);
                 return false;
     		}
     		clinicObj.each(function(key,value){
     			if(clinicObj.length-1==key){
     				 clinicCheck+='"'+key+'":'+$(value).attr("data-clinic_id")+''
     			}else{
     				 clinicCheck+='"'+key+'":'+$(value).attr("data-clinic_id")+','
     			}
           	
            });
     		clinicCheck+='}';
     		//2.获取选中业务员ID
     		salemanId=$('#select-one').find('.selected').attr('data-saleman_id');
     		if(salemanId===undefined){
     			 $('#iosDialog2').find('.sure-info').html('请选择被分配人员');
                 $('#iosDialog2').show(200);
                 return false;
     		}
     		$.ajax({
                url: "",
                type: 'POST',
                data: {'clinics':clinicCheck,'salemanId':salemanId},
                async: false,
                cache: false,
               	dataType:"json",
                success: function (returndata) {
                	//session失效
               	 	returnStatus=returndata.code;
               	 	if(returndata.code==2028){
               	 		sessioncode=2028;
               	 		nosesstion_url=returndata.data;
	        	       	 	$('.weui-dialog__bd').html(returndata.msg);
	        	     		$('#confirm_dialog').css('display','block');
               	 	}else{
	               	 	$('.weui-dialog__bd').html(returndata.msg);
	             		$('#confirm_dialog').css('display','block');
               	 	}
                },
                error: function (returndata) {
                		$('.weui-dialog__bd').html(returndata.msg);
             		$('#confirm_dialog').css('display','block');
                }
            });
			$(document).on('click','.weui-dialog__btn_primary',function(){
				if(sessioncode==2028){
					window.location.href=nosesstion_url;
				}else{
					if(returnStatus==200){
						location.href='/Home/SaleManager/County/distribution';
					}else{
						return false;
					}
					
				}
			})
            //$("#ok-success").css("display","-webkit-box")
         })
         // 关闭弹窗
         $("#ok-success .simple-close").click(function(){
            $("#ok-success").css("display","-webkit-box;")
         })
         
         $('.sure-btn').click(function(){
            $('#iosDialog2').hide(200);
            return false;
         })
   })
 </script>
</html>